<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="form-wrap">
            <div class="layui-card">
                <div class="layui-card-header">请假</div>
                <div class="layui-card-body">
                    <div class="layui-form" action="" lay-filter="component-form-element">
                        <div class="layui-row layui-col-space10 layui-form-item">
                            <div class="layui-col-lg6">
                                <label class="layui-form-label">员工姓名：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="fullname" id="username" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-lg6">
                                <label class="layui-form-label">请假类型：</label>
                                <div class="layui-input-block">
                                    <select name="type" id="type" lay-verify="required" lay-filter="aihao">
                                        <option value=""></option>
                                        <option value="病假">病假</option>
                                        <option value="事假">事假</option>
                                        <option value="产假">产假</option>
                                        <option value="婚假">婚假</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                            <div class="layui-col-lg6">
                                <label class="layui-form-label">开始时间：</label>
                                <div class="layui-input-block">
                                    <input type="date" name="startime" id="startime" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">结束时间：</label>
                            <div class="layui-input-block">
                                <input type="date" name="endtime" id="endtime" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">天数：</label>
                            <div class="layui-input-block">
                                <input type="text" name="day" id="day" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">请假事由：</label>
                            <div class="layui-input-block">
                                <textarea name="other" id="why" placeholder="" class="layui-textarea"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">在外请遵守防疫要求</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="agreement" id="agreement" title="同意" lay-skin="primary" checked>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" type="button" id="submit" lay-submit lay-filter="component-form-element">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="../lib/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,form = layui.form;

        form.render(null, 'component-form-element');
        element.render('breadcrumb', 'breadcrumb');

        form.on('submit(component-form-element)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
</script>
</body>
<script>
        $("#submit").click(function () {
            var flag = $("#agreement").is(":checked");
            var leave = {};
            leave.type = $("#type").val();
            leave.start = $("#startime").val();
            leave.end = $("#endtime").val();
            leave.day = $("#day").val();
            leave.uname = $("#username").val();
            leave.reason = $("#why").val();
            if(flag==true)
            {
                $.ajax({
                    url: '/Personnel/leave/addleave',
                    type: 'post',
                    data: JSON.stringify(leave),
                    contentType: "application/json;charset=utf-8",
                    dataType: 'json',
                    success: function (d) {
                        if (d.fig == "success") {
                            alert("提交成功");
                            loaction.href="Leave.html";
                        } else {
                            alert("提交失败");
                        }
                    }
                })
            }
            else{
                alert("不遵守防疫规定，无法请假");
            }
        })
</script>

</html>